/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn;

import java.lang.reflect.Constructor;

/**
 * <p>Project: javase2203 - Reflection4
 * <p>Powered by webrx On 2022-08-11 17:45:41
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Reflection4 {
    public static void main(String[] args) throws Exception {
        //Class<? extends Book> c = Book.class;
        //反射类
        var c = Book.class;

        //根据类，反射出实例对象
        //Constructor<?>[] cs = c.getConstructors();
        //for (Constructor<?> cons : cs) {
        //    System.out.println(cons.getName());
        //    System.out.println(Arrays.toString(cons.getParameterTypes()));
        //}

        //反射类的 反射出的有参构造方法的.newInstance() 方法来实例化了对象。
        Constructor<Book> con = c.getConstructor(int.class,String.class,double.class);
        Book book = con.newInstance(100,"《java项目实战》",56.8);
        System.out.println(book);
        System.out.println(book.getId());
        System.out.println(book.getName());
        System.out.println(book.getPrice());

    }
}
